<?php
/**我的消息通知
 */

namespace Wap\Controller;
use Common\Model\NoticeModel;
use Common\Model\UserModel;
use Wap\BaseController;
class NoticeController extends BaseController{
    const SYSTEM_ICON = "Public/Admin/img/msgIcon3.png";//系统消息图标
    //我的消息通知
    public function message(){
        $uid = session('uid')+0;

        if(!$uid) redirect(U('User/login')."&uri=".urlencode($_SERVER['REQUEST_URI']));
        session('noticeFlag',0);

        //是否当日首次签到
        signAssignWap($uid,$this->smarty);

        $this->smarty->assign("title","消息中心");
        $this->smarty->display("User_v2/myNotice.html");
    }

    //加载更多
    function loadmore(){
        $page = I('get.page',1,'intval');

        $uid = session('uid');
        $message = NoticeModel::myAllMessage($uid,$page,7);
        $notice = array();
        foreach($message['list'] as $key=>$value){
            if($value['type']==NoticeModel::NOTICE_TYPE_SYSTEM_MSG){
                if($value['target']==NoticeModel::NOTICE_TARGET_POINTLOTTERY){
                    $value['link'] = u('PointLottery/myRecord');
                }
                $notice[] = array(
                    'id'        =>$value['id'],
                    'icon'      =>self::SYSTEM_ICON,
                    'name'      =>$value['title'],
                    'content'   =>msubstr($value['content'],0,32),
                    'link'      =>$value['link'],
                    'time'      =>ReadableTime($value['noticeTime']),
                );
            }else if($value['type']==NoticeModel::NOTICE_TYPE_COMMENT){
                $notice[] = array(
                    'id'        =>$value['id'],
                    'icon'      =>UserModel::getHeadPicFullPath($value['icon']),
                    'name'      =>$value['title'],
                    'content'   =>msubstr($value['content'],0,32),
                    'link'      =>"wap.php?m=Wap&c=article&a=detail&id=".$value['objID'],
                    'time'      =>ReadableTime($value['noticeTime']),
                );
            }else if($value['type']==NoticeModel::NOTICE_TYPE_PRAISE){
                $notice[] = array(
                    'id'        =>$value['id'],
                    'icon'      =>UserModel::getHeadPicFullPath($value['icon']),
                    'name'      =>$value['title'],
                    'content'   =>msubstr($value['content'],0,32),
                    'link'      =>"wap.php?m=Wap&c=article&a=detail&id=".$value['objID'],
                    'time'      =>ReadableTime($value['noticeTime']),
                );
            }

        }
        $this->smarty->assign('list',$notice);
        $html= $this->smarty->fetch('User_v2/myNotice_list.html');
        $this->ajaxReturn(array('status'=>0, 'dataHTML'=>$html,'total'=>$message['total'], 'isPage'=>$message['nextPage']));

    }
    
    //删除一条数据
    public function delete(){
        $id=I("get.id",null,'intval');
        $uid=session('uid')+0;
        $del=NoticeModel::del($id,$uid);

        $this->ajaxReturn($del);
    }
//    清空
    public function delAll(){
        $uid=session('uid');
        $del = NoticeModel::delAll($uid);

        $this->ajaxReturn($del);
    }

}